import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home'
import Product from '@/views/Product'
import About from '@/views/About'
import BlockLighthouse from '@/views/products/BlockLighthouse'

import RootDefault from '@/components/layout/RootDefault'

const DEFAULT_TITLE = '数字无界官网'

const routes = [
  { path: '/',
    name: 'RootDefault',
    component: RootDefault,
    children: [
      {
        path: '',
        name: 'Home',
        component: Home,
      },
    ]
  },
  { path: '/product',
    name: 'Product',
    component: Product,
    meta: {
      suffix: '- 产品'
    }
  },
  { path: '/about',
    name: 'About',
    component: About,
    meta: {
      suffix: '- 关于我们'
    }
  },
  { path: '/products/blockLighthouse',
    name: 'BlockLighthouse',
    component: BlockLighthouse,
    meta: {
      title: '区块灯塔官网',
      suffix: ''
    }
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to,from,next)=>{
  const suffix = to.meta.suffix || ''
  const title = (to.meta.title || DEFAULT_TITLE) + suffix

  window.document.title = title
  next()
})

export default router